package com.wmm.job5;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

public class Poker {

    public static void main(String[] args) {
        //存储扑克牌  索引值  牌的内容
        HashMap<Integer,String> pokerIndex = new HashMap<Integer, String>();
        //索引值
        ArrayList<Integer> index = new ArrayList<Integer>();
        String[] numbers = {"2","A","K","Q","J","10","9","8","7","6","5","4","3"};

        pokerIndex.put(0,"大王");
        index.add(0);
        pokerIndex.put(1,"小王");
        index.add(1);

        int num = 2;
        for (int i=0;i<numbers.length;i++){
            for(int j=0;j<4;j++){
                pokerIndex.put(num,numbers[i]);
                index.add(num);
                num++;
            }
        }

        //洗牌
        Collections.shuffle(index);

        //声明存储扑克牌的对象
        ArrayList<Integer> player01 = new ArrayList<>();
        ArrayList<Integer> player02 = new ArrayList<>();
        ArrayList<Integer> player03 = new ArrayList<>();
        ArrayList<Integer> diPai = new ArrayList<>();
        System.out.println("游戏开始:");
        // 分牌
        for (int i = 0;i<index.size();i++){
            if (i>=51){
                diPai.add(index.get(i));
            }else if (i%3 == 0){
                player01.add(index.get(i));
                System.out.println("发给玩家1的牌：" + pokerIndex.get(index.get(i)));
            }else if (i%3 == 1){
                player02.add(index.get(i));
                System.out.println("发给玩家2的牌：" + pokerIndex.get(index.get(i)));
            }else if (i%3 == 2){
                player03.add(index.get(i));
                System.out.println("发给玩家3的牌：" + pokerIndex.get(index.get(i)));
            }
        }

        //排序
        Collections.sort(player01);
        Collections.sort(player02);
        Collections.sort(player03);
        Collections.sort(diPai);

        //看牌
        show("玩家1",player01,pokerIndex);
        show("玩家2",player02,pokerIndex);
        show("玩家3",player03,pokerIndex);
        show("底牌",diPai,pokerIndex);
    }

    public static void show(String name,ArrayList list, HashMap hashMap){
        System.out.println(name+"的牌：");
        for (int i=0;i<list.size();i++){
            System.out.print(hashMap.get(list.get(i)) + " ");
        }
        System.out.println();
    }
}
